<?php
namespace shenka\controllers;

use Yii;
use yii\web\Controller;
use shenka\models\UserInfo;
use yii\db\Query;
use shenka\controllers\classes\QueryClasses;
/*
* @author admin 
* @class Art
* @desc 美术棒
*/

class ArtController extends Controller {
	/*
	* @author admin 
	* @function List
	* @desc 美术棒用户列表
	*/
	public function actionList(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '美术棒';
		// xin  获取美术棒用户列表数据
		$data['user'] = UserInfo::find()->asArray()->all();
		return $this->render('list',$data);
	}
	/*
	* @author admin 
	* @function Gender
	* @desc 美术棒性别占比
	*/
	public function actionGender(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '美术棒';
		$re = UserInfo::find()->select(["count(id) as count",'gender'])->groupBy(['gender'])->asArray()->all();
		$data = ['female'=>0,'male'=>0,'unk'=>0];
		foreach($re as $k => $v){
			if(is_numeric($v['gender']) && $v['gender'] == 0){
				$data['female'] += (int)$v['count'];
			}
			if(is_numeric($v['gender']) && $v['gender'] == 1){
				$data['male'] += (int)$v['count'];
			}
			if($v['gender'] == ''){
				$data['unk'] += (int)$v['count'];
			}
		}
		$gender = json_encode($data);

		return $this->render('gender',['gender' => $gender]);
	}
	/*
	* @author admin 
	* @function Age
	* @desc 美术棒性别占比
	*/
	public function actionAge(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '美术棒';

		return $this->render('age');
	}
	/*
	* @author admin 
	* @function Level
	* @desc 美术棒关卡进度分布
	*/
	public function actionLevel(){
		$view = Yii::$app->view;
		$view->params['layout_data'] = '美术棒';
		$data = UserInfo::find()->select('art_level')->asArray()->all();
		$temp = '';
		foreach($data as $k){
			$temp = $temp . $k['art_level'];
		}
		$data = array_count_values(explode(',',$temp));
		ksort($data);
		array_shift($data);
		$level = json_encode([array_keys($data),array_values($data)]);
		//var_dump($data);exit;
		return $this->render('level',['level' => $level]);
	}


}